@extends('main')

@section('tip', $post->title)

@section('content')
<div class="row">
    <div class="col-md-10 col-md-offset-1">
        <h2>{{ $post->title }}</h2>
        <span style="font-size:12px;color:#aaa"><strong>发布时间:</strong>{{ $post->created_at }} &nbsp; &nbsp; 
        <strong>最后修改:</strong>{{ $post->updated_at }}</span>
        <hr>
        {!! $post->body !!}
        <hr>
        <strong>分类:</strong> {{ $post->category->name }} &nbsp; &nbsp;
        <strong>标签:</strong>
        @foreach($post->tag as $tag)
        <span class="label label-default">{{ $tag->name }}</span>
        @endforeach
    </div>

    <div class="col-md-10 col-md-offset-1">
    <br>
    <h4><strong>留言:</strong></h4>

    <div class="panel panel-default" style="padding:10px 35px 10px 10px">
    @foreach($post->comment as $comment)  
        <div class="media" style="padding:3px 10px">
            <?php 
            $url = 'https://cn.gravatar.com/avatar/';
            $has = md5(strtolower(trim($comment->email)));
            $avatar = $url.$has.'?s=64&d=identicon';
            ?>
            <a href="#" class="media-left">
                <img src="{{ $avatar }}" alt="{{ $comment->name }}">
            </a>
            <div class="media-body">
                <h4 class="media-heading">
                    {{ $comment->name }}  
                </h4>
                <p>{{ $comment->comment }}</p>
            </div>
        </div>
    @endforeach
    </div>
    </div>

    <div class="col-md-10 col-md-offset-1">
        {!! Form::open(['route'=>'comment.store', 'method'=>'POST']) !!}
        {!! Form::hidden('post_id', $post->id) !!}
        <div class="row">
            <div class="col-md-6">
                {!! Form::label('name', '称呼:') !!}
                {!! Form::text('name', null, ['class'=>'form-control']) !!}
                {!! Form::label('email','邮箱:') !!}
                {!! Form::email('email', null, ['class'=>'form-control']) !!}
            </div>

            <div class="col-md-6">
                {!! Form::label('comment','评论(最多255个字):') !!}
                {!! Form::textarea('comment', null, ['class'=>'form-control', 'rows'=>'4', 'style'=>'resize:none']) !!}
            </div>
        </div>
        <div class="row" style="margin:10px 1px">
        {!! Form::submit('发表评论', ['class'=>'btn btn-primary']) !!}
        </div>
        {!! Form::close() !!}
    </div>
</div>
@endsection
